﻿using BMSQ.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BMSQ.Admin.GoodsType1
{
    public partial class Modify : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindBusinessType();

                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    string GT1_ID = Request.Params["id"];
                    ShowInfo(GT1_ID);
                }
            }
        }

        private void BindBusinessType()
        {
            BindDrowDownList(ddlBusinessType, new BLL.Business_Type().GetAllList(), "B_TypeName", "B_TypeID", true);
        }

        private void ShowInfo(string GT1_ID)
        {
            BLL.Goods_Type1 bll = new BLL.Goods_Type1();
            Model.Goods_Type1 model = bll.GetModel(GT1_ID);
            this.lblGT1_ID.Text = model.GT1_ID;
            this.txtGT1_Name.Text = model.GT1_Name;
            ddlBusinessType.SelectedValue = model.B_TypeID;

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtGT1_Name.Text.Trim().Length == 0)
            {
                strErr += "GT1_Name不能为空！\\n";
            }
            if (ddlBusinessType.SelectedIndex < 1)
            {
                strErr += "B_TypeID不能为空！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string GT1_ID = this.lblGT1_ID.Text;
            string GT1_Name = this.txtGT1_Name.Text;
            string B_TypeID = ddlBusinessType.SelectedValue;


            Model.Goods_Type1 model = new BLL.Goods_Type1().GetModel(GT1_ID);
            model.GT1_ID = GT1_ID;
            model.GT1_Name = GT1_Name;
            model.B_TypeID = B_TypeID;

            BLL.Goods_Type1 bll = new BLL.Goods_Type1();
            bll.Update(model);
            MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}